<?php


/**
 * Model with Flickr methods.
 */
class Flickr extends Psa_Plugin_Model{


	/**
	 * Searches Flickr using Zend_Service_Flickr
	 */
	function search_photos($search_string){
		
		// validate input
		$validator = new Psa_Validator();
		$validator->add_required($search_string, 'string');
		$validator->validate();
		
		global $PSA_CFG;
		
		// add Zend Framework to include path
		psa_add_include_path($PSA_CFG['folders']['basedir'] . '/../examples/example_app2');
		
		// call zend loader
		require_once "Zend/Loader.php";
		Zend_Loader::registerAutoload();
		
		// search Flickr using Zend_Service_FlickrS
		$flickr = new Zend_Service_Flickr('ee701d2bfb0870582186ad1d30ec0161');
		$results = $flickr->tagSearch($search_string);
		
		// put results into psa_result object
		foreach($results as $result){
			$this->psa_result->images[] = $result->Small->uri;
		}
		
		// put search string into psa_result object to be shown on page after refresh
		$this->psa_result->search_string = $search_string;
	}
}
?>